# -*- coding:utf-8 -*-
from pydantic import Field, BaseModel
from sqlalchemy import Column, Integer, String, DateTime, Enum, DECIMAL, Float, TEXT
from core.curd import Base, TimestampMixin
from typing import List
from datetime import datetime


class SysUser(Base, TimestampMixin):
    """
    测试表
    """
    __tablename__ = 'sys_user'

    id = Column(Integer, nullable=False, autoincrement=True, primary_key=True, comment='id')
    username = Column(String(50), nullable=False, comment='用户名')
    password = Column(String(100), comment='密码')
    salt = Column(String(64), comment='密码盐')
    real_name = Column(String(50), comment='姓名')
    avatar = Column(String(200), comment='头像')
    gender = Column(Integer, comment='性别   0：男   1：女   2：未知')
    email = Column(String(100), comment='邮箱')
    mobile = Column(String(20), comment='手机号')
    org_id = Column(Integer, comment='机构ID')
    super_admin = Column(Integer, comment='超级管理员   0：否   1：是')
    status = Column(Integer, comment='状态  0：停用   1：正常')
    tenant_id = Column(Integer, comment='租户ID')
    version = Column(Integer, comment='版本号')
    deleted = Column(Integer, comment='删除标识  0：正常   1：已删除')
    creator = Column(Integer, comment='创建者')
    updater = Column(Integer, comment='更新者')

    def dict(self):
        return {
            'id': self.id,
            'username': self.username,
            'real_name': self.real_name,
            'avatar': self.avatar,
            'gender': self.gender,
            'email': self.email,
            'mobile': self.mobile,
            'org_id': self.org_id,
            'status': self.status
        }

class SysUserRole(Base):
    """
    用户和角色关联表
    """
    __tablename__ = 'sys_user_role'

    user_id = Column(Integer, primary_key=True, nullable=False, comment='用户ID')
    role_id = Column(Integer, primary_key=True, nullable=False, comment='角色ID')
    create_time = Column(DateTime, comment='创建时间', default=datetime.now())
    update_time = Column(DateTime, comment='更新时间', default=datetime.now())


class SysUserPost(Base):
    """
    用户与岗位关联表
    """
    __tablename__ = 'sys_user_post'

    user_id = Column(Integer, primary_key=True, nullable=False, comment='用户ID')
    post_id = Column(Integer, primary_key=True, nullable=False, comment='岗位ID')
    create_time = Column(DateTime, comment='创建时间', default=datetime.now())
    update_time = Column(DateTime, comment='更新时间', default=datetime.now())



class CreateSysUser(BaseModel):
    username: str = Field(comment='用户名', max_length=50)
    password: str = Field(comment='密码', max_length=100)
    real_name: str = Field(comment='姓名', max_length=50)
    gender: int = Field(comment='性别   0：男   1：女   2：未知')
    email: str = Field(comment='邮箱', max_length=100)
    mobile: str = Field(comment='手机号', max_length=20)
    org_id: int = Field(comment='机构ID')
    status: int = Field(comment='状态  0：停用   1：正常')
    postIdList: List[int] = Field(comment="岗位")
    roleIdList: List[int] = Field(comment="角色")


class UpdateSysUser(BaseModel):
    id: int = Field(comment='id')
    username: str = Field(comment='用户名', max_length=50)
    password: str = Field(comment='密码', max_length=100)
    real_name: str = Field(comment='姓名', max_length=50)
    gender: int = Field(comment='性别   0：男   1：女   2：未知')
    email: str = Field(comment='邮箱', max_length=100)
    mobile: str = Field(comment='手机号', max_length=20)
    org_id: int = Field(comment='机构ID')
    status: int = Field(comment='状态  0：停用   1：正常')
    postIdList: List[int] = Field(comment="岗位")
    roleIdList: List[int] = Field(comment="角色")
